package com.atguigu.bigdata.spark.sql;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.sql.*;
public class Spark01_SparkSQL_Basic_JAVA {
    public static void main(String[] args) throws AnalysisException {
        // TODO 准备环境
        SparkConf conf = new  SparkConf().setMaster("local[*]").setAppName("sparkSQL");
        SparkSession spark = SparkSession.builder().config(conf).getOrCreate();
        // TODO 执行逻辑操作
        // TODO DataFrame
        // DataFrame其实是特定泛型的DataSet
        Dataset<Row> df   = spark.read().json("datas/user.json");
        //df.show();
//
        df.createGlobalTempView("user");
        //spark.sql("select * from user").show();
//        spark.sql("select age, username from user").show();
       spark.sql("select avg(age) from user").show();

        // 在使用DataFrame时，如果涉及到转换操作，需要引入转换规则

        //df.select("age").show();


        spark.close();

    }
}
